from src.Dao.ProductDao import ProductDao
from src.Utils.index import colored_text,ResponseService,productListgroupbyKey

productDB = ProductDao()


class ProductService:
    def __init__(self):
        pass
    
    def insertProduct(self,name,price,oldPrice,sellCount,rating,icon,image,typeId):
        result = productDB.insertProduct(name,price,oldPrice,sellCount,rating,icon,image,typeId)
        if not result:
            return ResponseService.error(result,"插入失败")
        else:
            return ResponseService.success(result,"插入成功")
        
    def getProductList(self):
        result = productDB.getProductList()
        result = productListgroupbyKey(result,'typeId')
        if not result:
            return ResponseService.error(result,"查询商品列表失败")
        else:
            return ResponseService.success(result,"查询商品列表成功")